<?php

namespace App\Http\Controllers\Admin\Auth;

use App\Http\Controllers\Admin\BaseController;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;

class ResetPasswordController extends BaseController
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset requests
    | and uses a simple trait to include this behavior. You're free to
    | explore this trait and override any methods you wish to tweak.
    |
    */

    use ResetsPasswords;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
    }

    public function index()
    {
        return view('auth.passwords.reset');
    }

    public function reset(Request $request)
    {
        $this->validate($request, [
            'password_old' => 'required',
            'password' => 'required|min:6'
        ],[
            'password.min' => '密码最少6位'
        ]);

        $data = $request->all();

        if(!\AdminService::resetPassword($data['password_old'], $data['password'])){
            return back()->withErrors('密码错误');
        }

        return $this->success('修改密码成功');
    }
}
